home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 10274 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.7 KB  |  57 lines

  1. Path: news.netppl.fi!usenet
  2. From: Jouko Holopainen <jouko.holopainen@xnet.otm.fi>
  3. Newsgroups: comp.arch.arithmetic,comp.lang.c,comp.lang.c++
  4. Subject: Re: Access carry flag from C
  5. Date: Wed, 06 Mar 1996 09:01:48 +0200
  6. Organization: X-Net Oy
  7. Message-ID: <313D385C.4651@xnet.otm.fi>
  8. References: <4h1veoINNlns@anvil.ugrad.cs.ubc.ca> <fgrieu-0403961143580001@ppp78.micronet.fr> <4hhbt8$1d3o@b.stat.purdue.edu> <Dnssxu.JGy@cwi.nl>
  9. NNTP-Posting-Host: 194.136.175.71
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=iso-8859-1
  12. Content-Transfer-Encoding: 8bit
  13. X-Mailer: Mozilla 2.0 (Win95; I)
  14.  
  15. Dik T. Winter wrote:
  16. > In article <4hhbt8$1d3o@b.stat.purdue.edu> hrubin@b.stat.purdue.edu (Herman Rubin) writes:
  17. >  > In article <fgrieu-0403961143580001@ppp78.micronet.fr>,
  18. >  > Franτois Grieu <fgrieu@micronet.fr> wrote:
  19. >  >
  20. >  > >   if (x + yl < yl) ++yh; /* test for overflow on next line */
  21. >  > >   yl += x;
  22. > ...
  23. >  > Notice that in the above code, each addition must be performed twice.
  24.  
  25. > Wrong.  Even a mediocre compiler will optimize this away.
  26.  
  27. Just for fun, let's compare carry and non-carry assembly 
  28. (kinda x86):
  29. Without carry:
  30.   mov tmp, yl
  31.   add tmp, x
  32.   cmp tmp, yl
  33.   jmp lt, noadd
  34.   inc yh
  35. noadd:
  36.   mov yl, tmp
  37.  
  38. With carry:
  39.   add yl, x
  40.   adc yh, 0
  41.  
  42. See any difference?
  43.  
  44. Optimizing an addition away might in fact slow down. It just 
  45. depends whether tmp and/or x,yl,yh are register variables.
  46. Anyway I know of no processor where reg+reg->reg addition takes 
  47. longer than reg->reg move.
  48.  
  49. > But the code above also works on machines without carry bit.
  50.  
  51. Yes. In fact, the latter cannot be produced with C
  52. (or any other high level language, for that matter). 
  53. Which was the original point.
  54.  
  55.   @jhol
  56.